package com.yalu.dao.data.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Repository;

import com.yalu.dao.base.impl.BaseJDBCDaoImpl;
import com.yalu.dao.data.SalesReportDao;
import com.yalu.util.ReportExportUtil;

import core.report.yearReport.bean.CustomSalesReportDataBean;
import core.report.yearReport.bean.SalesReportDataBean;

@Repository
public class SalesReportDaoImpl extends BaseJDBCDaoImpl implements SalesReportDao{

	@Override
	public List<SalesReportDataBean> getSalesReportDataBeanList(String dateType,String beginTime,String endTime,String lastYearThisWeekFlag, String compareYear) {
		List<SalesReportDataBean> dataList = new ArrayList<SalesReportDataBean>();
		String sql = ReportExportUtil.getSalesReportSql(dateType, beginTime,endTime,lastYearThisWeekFlag,compareYear);
		SqlRowSet rs = executeQuery(sql);
		System.out.println(sql);
		
		double allStoreTotalAmount=0;
		while(rs.next()){
			SalesReportDataBean bean = SalesReportDataBean.createSalesReportDataBeanByDateType(dateType);
			bean.setProperties(rs);
			allStoreTotalAmount+=bean.getTotalAmount();
			dataList.add(bean);
		}
		for(SalesReportDataBean dataBean : dataList){
			double saleRate = dataBean.getTotalAmount()/allStoreTotalAmount;
			dataBean.setSale_rate(saleRate);
		}
		return dataList;
	}


}